<template>
  <div>
    <el-menu
      :default-active="$route.path"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      background-color="#00B98D"
      text-color="#fff"
      active-text-color="#fff"
    >
      <el-menu-item :index="item.url+''" v-for="(item,index) in menuList" :key="index">{{item.name}}</el-menu-item>
    </el-menu>
  </div>
</template>

<script>
import { menusList } from "@/service/Api.js"; // 接口

import { mapMutations } from "vuex";

export default {
  name: "NavMenu",
  props: ["menuList"],
  data() {
    return {
      open: true,
      showRoot: false,
    };
  },

  methods: {
    ...mapMutations(["SET_MENUID"]),
    handleSelect(key, keyPath) {
      let list = this.menuList.filter((el) => {
        return el.menuUrl == key;
      });
      if (list.length > 0) {
        this.SET_MENUID(parseInt(list[0].menuId));
      }

      this.$router.push({ path: key });
    },
    // getMenus(){
    //   menusList().then(result => {
    //     if (result.code == 0) {
    //       this.menus = result.data;
    //     } else {

    //     }
    //   },err => {
    //
    //   })
    // }
  },
  mounted() {
    // this.getMenus();
  },
};
</script>

<style scoped>
.el-menu {
  width: 100%;
}
.el-menu li:hover,
.menu .is-active {
  background: #009f6d !important;
  border-bottom-color: #009f6d !important;
}
.el-menu--horizontal > .el-menu-item {
  width: 8%;
  min-width: 100px;
  text-align: center;
  height: 48px;
  line-height: 48px;
}
</style>

